<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Package">

  <!-- 
  	****************************************
  	* IMPORTS
	****************************************
  -->
  <PropertyGroup>
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\..\Tools\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
  	<MSBuildUmbracoTasksPath>$(MSBuildProjectDirectory)\..\Tools\MSBuildUmbracoTasks</MSBuildUmbracoTasksPath>
  </PropertyGroup>

  <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" />
  <Import Project="$(MSBuildUmbracoTasksPath)\MSBuild.Umbraco.Tasks.Targets" />

  <!-- 
  	****************************************
  	* PROPERTIES
	****************************************
  -->
  <PropertyGroup>
	<PackageVersion>1.0.0</PackageVersion>
  </PropertyGroup>

  <PropertyGroup>
	<RootDir>$(MSBuildProjectDirectory)</RootDir>
	<BuildDir>$(RootDir)\Build</BuildDir>
	<PackageDir>$(RootDir)\..\Package</PackageDir>
	<ProjectDir>$(RootDir)</ProjectDir>
  </PropertyGroup>
  
  <!-- 
  	****************************************
  	* TARGETS
	****************************************
  -->
  
  <!-- CLEAN -->
  <Target Name="Clean">
	  <RemoveDir Directories="$(BuildDir)" Condition="Exists('$(BuildDir)')" />
	  <MakeDir Directories="$(BuildDir)" />
  </Target>

  <!-- UPDATE ASSEMBLEY VERSION -->
  <Target Name="UpdateAssemblyInfo" DependsOnTargets="Clean">
    <FileUpdate
          Encoding="ASCII"
          Files="$(ProjectDir)\Properties\AssemblyInfo.cs"
          Regex="AssemblyVersion\(&quot;.*&quot;\)\]"
          ReplacementText="AssemblyVersion(&quot;$(PackageVersion)&quot;)]" />
    <FileUpdate
          Encoding="ASCII"
          Files="$(ProjectDir)\Properties\AssemblyInfo.cs"
          Regex="AssemblyFileVersion\(&quot;.*&quot;\)\]"
          ReplacementText="AssemblyFileVersion(&quot;$(PackageVersion)&quot;)]" />
  </Target>
  
  <!-- COMPILE -->
  <Target Name="Compile" DependsOnTargets="UpdateAssemblyInfo">
	  <MSBuild Projects="$(ProjectDir)\Contour.Contrib.csproj" Properties="Configuration=Release" />
  </Target>
    
  <!-- PREPAIRE FILES --> 
  <Target Name="PrepairFiles" DependsOnTargets="Compile">
    <ItemGroup>
      <BinFiles Include="$(ProjectDir)\Bin\Contour.Contrib.dll" />
	  <BinFiles Include="$(ProjectDir)\Bin\Recaptcha.dll" />
	  <BinFiles Include="$(ProjectDir)\Bin\PackageActionsContrib.dll" />
      <PluginFiles Include="$(ProjectDir)\Resources\umbraco\plugins\umbracoContour\images\*.*" />
	  <PluginFiles1 Include="$(ProjectDir)\Resources\umbraco\plugins\umbracoContour\images\fieldtypes\*.*" />
      <PackageFile Include="$(RootDir)\Package.xml" /> 
    </ItemGroup>
	<Copy SourceFiles="@(BinFiles)" DestinationFolder="$(BuildDir)\Bin" />
	<Copy SourceFiles="@(PluginFiles)" DestinationFolder="$(BuildDir)\umbraco\plugins\umbracoContour\images" />
	<Copy SourceFiles="@(PluginFiles1)" DestinationFolder="$(BuildDir)\umbraco\plugins\umbracoContour\images\fieldtypes" />
	<Copy SourceFiles="@(PackageFile)" DestinationFolder="$(BuildDir)" />
  </Target> 
  
  <!-- MANIFEST -->
  <Target Name="Manifest" DependsOnTargets="PrepairFiles">
	<ItemGroup>
      <ManifestFiles Include="$(BuildDir)\**\*" Exclude="$(BuildDir)\Package.xml" />
    </ItemGroup>
	<ManifestUpdate ManifestFile="$(BuildDir)\Package.xml"
		WorkingDirectory="$(BuildDir)"
		PackageVersion="$(PackageVersion)"
	    Files="@(ManifestFiles)" />
  </Target> 
    
  <!-- PACKAGE -->
  <Target Name="Package" DependsOnTargets="Manifest">
	<ItemGroup>
      <PackageFiles Include="$(BuildDir)\**\*.*" />
  	</ItemGroup>
	<Package ManifestFile="$(BuildDir)\Package.xml"
       WorkingDirectory="$(BuildDir)"
       OutputDirectory="$(PackageDir)"
	   Files="@(PackageFiles)" /> 
  </Target> 
  
</Project>